package com.ygqh.baby.controller.admin;

import com.ygqh.baby.ao.BillStatus;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.YgWholesalerBillRecord;
import com.ygqh.baby.service.YgWholesalerBillRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.Map;

/**
 * @author: sunshuo
 * @date: 2018/12/12 11:26
 */
@Controller
@RequestMapping("admin/wholesalebill")
public class WholeSalerBillRecordController extends BaseController<YgWholesalerBillRecord, Long> {

	@Autowired
	private YgWholesalerBillRecordService ygWholesalerBillRecordService;

	/**
	 * 查询结算列表
	 *
	 * @param queryInfo
	 * @param wholesalerName
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@RequestMapping("searchBill")
	@ResponseBody
	public Map<String, Object> searchBill(QueryInfo queryInfo, String wholesalerName, Date startDate, Date endDate, String billCode, BillStatus billStatus) {
		ResultSet<YgWholesalerBillRecord> resultSet = ygWholesalerBillRecordService.search(queryInfo, wholesalerName, startDate, endDate, billCode, billStatus);
		return resultSet.toDatatables(null);
	}

	/**
	 * 更新结算单状态
	 *
	 * @param billRecord
	 * @return
	 */
	@RequestMapping("updateBillStatus")
	@ResponseBody
	public Message updateBillStatus(YgWholesalerBillRecord billRecord) {
		billRecord.setUpdateBy(getSession().getTrueName());
		billRecord.setUpdateTime(new Date());
		ygWholesalerBillRecordService.updateBillStatus(billRecord);
		return Message.success(null);
	}

}
